"""typeidea URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/4.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
import xadmin
from django.conf import settings
from django.conf.urls.static import static
from django.contrib import admin
# from django.urls import path
from django.conf.urls import url, include
from rest_framework.routers import DefaultRouter

from .autocomplete import CategoryAutocomplete, TagAutocomplete
from .custom_site import custom_site
# from blog.views import post_list
# from config.views import links

# from blog.views import post_detail

from blog.views import (IndexView, CategoryView, TagView, SearchView, AuthorView)
from config.views import LinkListView

from blog.views import PostDetailView

from comment.views import CommentView

from blog.rss import LatestPostFeed
from blog.sitemap import PostSitemap

# from blog.apis import post_list

from blog.apis import PostViewSet

router = DefaultRouter
router.register(r'post', PostViewSet, base_name='api-post')

urlpatterns = \
    [
        url(r'^api/', include(router.urls)),

        # url(r'^$', post_list, name='index'),
        url(r'^$', IndexView.as_view(), name='index'),
        # (?P<category_id>\d+) 把url这个位置的字符作为名为categoru_id的参数传递给post_list函数
        # 像一个仅由category_id标识而不是数字ID 标识的正则分组匹配
        # \d只能匹配一个数字，\d+才可以匹配多个数字
        # url(r'^category/(?P<category_id>\d+)/$', post_list, name='category-list'),
        url(r'^category/(?P<category_id>\d+)/$', CategoryView.as_view(), name='category-list'),

        # url(r'^tag/(?P<tag_id>\d+)/$', post_list, name='tag-list'),
        url(r'^tag/(?P<tag_id>\d+)/$', TagView.as_view(), name='tag-list'),

        # url(r'^post/(?P<post_id>\d+).html$', post_detail, name='post-detail'),
        url(r'^post/(?P<post_id>\d+).html$', PostDetailView.as_view(), name='post-detail'),
        url(r'^search/$', SearchView.as_view(), name='search'),
        url(r'^author/(?P<owner_id>\d+)/$', AuthorView.as_view(), name='author'),
        url(r'^links/$', LinkListView.as_view(), name='links'),
        url(r'^comment/$', CommentView.as_view(), name='comment'),

        url(r'^super_admin/', admin.site.urls, name='super-admin'),
        url(r'^admin/', xadmin.site.urls, name='xadmin'),

        url(r'^category-autocomplete/$', CategoryAutocomplete.as_view(), name='category-autocomplete'),
        url(r'^tag-autocomplete/$', TagAutocomplete.as_view(), name='tag-autocomplete'),

        url(r'^rss|feed/', LatestPostFeed(), name='rss'),
        # url(r'^sitemap\.xml$', sitemap_views.sitemap, {'sitemaps': {'posts': PostSitemap}}),

        url(r'^ckeditor/', include('ckeditor_uploader.urls')),

        # url(r'^api/post/', PostList.as_view(), name='post-list'),
        url(r'^api/post/', post_list, name='post-list'),

    ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
